# class Cat:
#     __name='小明' #加俩__表示私有
#     age=18
#
#     def __init__(self,age):
#         self.age =age
#     def print(self):
#         print('私有方法')
#         print(self.age)
#     def getName(self):
#         return self.__name
#
# cat=Cat(11)
# cat.print()
# cat1=Cat(12)
# cat1.print()
# print(cat.getName())
#
#
# class CarMini(Cat):
#     size=11
#     def __init__(self):
#         Cat.__init__(10)
#         self.size=size
#
#     def printSize(self):
#         print(self.size)
#
# car2=CarMini(111)
# car2.printSize()


class ParentClass:
    # 父类的初始化方法
    def __init__(self, name):
        self.name = name

    def greet(self):
        print(f"Hello, I am {self.name}")

# 子类继承 ParentClass
class ChildClass(ParentClass):
    def __init__(self, name, age):
        # 调用父类的构造方法
        super().__init__(name)
        self.age = age

    # 重写父类的方法
    def greet(self):
        print(f"Hello, I am {self.name} and I am {self.age} years old.")

# 创建实例
parent = ParentClass("ParentName")
parent.greet()  # 输出：Hello, I am ParentName

child = ChildClass("ChildName", 10)
child.greet()  # 输出：Hello, I am ChildName and I am 10 years old.



class Animal:
    def speak(self):
        pass  # 基类方法留空

class Dog(Animal):
    def speak(self):
        return "Woof!"

class Cat(Animal):
    def speak(self):
        return "Meow!"

def make_animal_speak(animal):
    print(animal.speak())

# 创建实例
dog = Dog()
cat = Cat()

# 使用多态
make_animal_speak(dog)  # 输出：Woof!
make_animal_speak(cat)  # 输出：Meow!




